
package trim.differentmaterials.generator.core;

import trim.differentmaterials.generator.columns.*;
import trim.differentmaterials.core.*;
import trim.differentmaterials.coefficients.*;

/**
 *
 * @author Podorov ALexander
 */

public class PositiveFormatGapBestPattern extends FormatGapBestPattern
{    
    public PositiveFormatGapBestPattern(TrimCore core, Coefficients coefficients)
    {
        super(core, coefficients);
    }

    public Gap getBestPattern(boolean isArtificialMode)
    {
        int[] items = new int[materialCount + formatCount];
        double maxEstimation = - Double.MAX_VALUE;
        int position = - 1;

        int coefficient = coefficients.getCoefficient(PositiveFormatGap.class).getValue(isArtificialMode);

        for (int i = 0; i < formatCount; i++)
        {
            double tempEstimation = dualVariables[i] - coefficient * formatOrder[i].getFormat().getLength();

            if (tempEstimation > maxEstimation)
            {
                maxEstimation = tempEstimation;
                position = i;
            }
        }

        items[position] = 1;

        return new PositiveFormatGap(items, maxEstimation, coefficients.getCoefficient(PositiveFormatGap.class), position);
    }
}
